<template>
  <div class="app-container">
    <el-tabs v-if="roleId != 3" v-model="activeName">
      <el-tab-pane label="设备管理" name="first">
        <list ref="list" :type="type" />
      </el-tab-pane>
      <el-tab-pane label="型号管理" name="second">
        <type ref="type" @setType="setType" />
      </el-tab-pane>
    </el-tabs>
    <list v-else ref="list" :type="type" />
  </div>
</template>

<script>
import Type from "./type";
import List from "./list";
import { deviceTypeList } from "@/api/manbing/equipment";
export default {
  name: "Equipment",
  components: { Type, List },
  data() {
    return {
      activeName: "first",
      type: [],
      roleId: sessionStorage.getItem("roleId"),
    };
  },
  created() {
    this.$nextTick(() => {
      this.$refs.list.init();
      if (this.roleId != 3) {
        this.$refs.type.init();
      } else {
        deviceTypeList({})
          .then((res) => {
            if (res.code == 200) {
              this.setType(res.data);
            }
          })
          .finally(() => {
            this.loading = false;
            this.tableLoading = false;
          });
      }
    });
  },
  methods: {
    setType(data) {
      this.type = data;
    },
  },
};
</script>
